﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace dkProfiler
{
    /// <summary>
    /// Base class with the code that's used by all the commands
    /// </summary>
    public abstract class ProfileCommand : ICommand
    {
        protected readonly ProfilerViewModel viewModel;

        public ProfileCommand(ProfilerViewModel viewModel)
        {
            this.viewModel = viewModel;
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public abstract void Execute(object parameter);
    }

    /// <summary>
    /// Command for when the user presses the New profile button
    /// </summary>
    public class NewProfileCommand : ProfileCommand
    {
        public NewProfileCommand(ProfilerViewModel viewModel) : base(viewModel) { }

        public override void Execute(object parameter)
        {
            viewModel.NewProfile();
        }
    }

    /// <summary>
    /// Command for when the user presses the Load profile button
    /// </summary>
    public class LoadProfileCommand : ProfileCommand
    {
        public LoadProfileCommand(ProfilerViewModel viewModel) : base(viewModel) { }

        public override void Execute(object parameter)
        {
            viewModel.LoadProfile();
        }
    }

    /// <summary>
    /// Command for when the user presses the Load profile button
    /// </summary>
    public class ImportCommand : ProfileCommand
    {
        public ImportCommand(ProfilerViewModel viewModel) : base(viewModel) { }

        public override void Execute(object parameter)
        {
            viewModel.Import();
        }
    }

    /// <summary>
    /// Command for when the user presses the Save profile button
    /// </summary>
    public class SaveProfileCommand : ProfileCommand
    {
        public SaveProfileCommand(ProfilerViewModel viewModel) : base(viewModel) { }

        public override void Execute(object parameter)
        {
            viewModel.SaveProfile();
        }
    }
}
